from rest_framework import serializers

from course import models

#教师的序列化
class TeatherSer(serializers.ModelSerializer):
    class Meta:
        model =models.TeacherModel
        fields = '__all__'

# 课程的序列化
class CourseSer(serializers.ModelSerializer):
    # 对教师的数据进行序列化，多出来一个字段
    tea=serializers.SerializerMethodField()
    def get_tea(self,obj):
        return {"name":obj.teacher.name,"job":obj.teacher.job,"headimg":obj.teacher.headimg,"intro":obj.teacher.intro}
    class Meta:
        model =models.CourseModel
        fields = '__all__'